﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EstoqueUnifeiADO
{
    public partial class frmMarcas : System.Web.UI.Page
    {
        protected string GrupoDeValidacao { get { return "frm" + this.ClientID; } }
        protected void AddError(String Erro)
        {
            this.Page.Validators.Add(new CustomValidator()
            {
                IsValid = false,
                ErrorMessage = Erro,
                Display = ValidatorDisplay.Dynamic,
                ValidationGroup = this.GrupoDeValidacao

            });
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ctrlItem.Key = gvList.SelectedValue.ToString();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            ctrlItem.SetReadOnly();
            gvList.DataBind();

        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Select"))
                switch (e.CommandArgument.ToString())
                {
                    case "Edit":
                        Button1_ModalPopupExtender.Show();
                        ctrlItem.SetEditMode();
                        break;
                    case "View":
                        Button1_ModalPopupExtender.Show();
                        ctrlItem.SetReadOnly();
                        break;
                }





        }

        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            if (e.Item.Value == "Novo")
            {
                Button1_ModalPopupExtender.Show();
                ctrlItem.SetInsertMode();
            }
        }

        protected void odsView_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                Exception erro = e.Exception.InnerException == null ? e.Exception : e.Exception.InnerException;
                AddError("Erro ao excluir o registro:" + System.Environment.NewLine + erro.Message);
            }
        }
    }
}